// Learn cc.Class:
//  - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/class.html
//  - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/class.html
// Learn Attribute:
//  - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html
//  - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html
//  - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/life-cycle-callbacks.html

cc.Class({
    extends: cc.Component,

    properties: {
        // foo: {
        //     // ATTRIBUTES:
        //     default: null,        // The default value will be used only when the component attaching
        //                           // to a node for the first time
        //     type: cc.SpriteFrame, // optional, default is typeof default
        //     serializable: true,   // optional, default is true
        // },
        // bar: {
        //     get () {
        //         return this._bar;
        //     },
        //     set (value) {
        //         this._bar = value;
        //     }
        // },
        isClick:0,
        mainPic:cc.Sprite,
        suit:cc.Sprite,
        point: cc.Label,
        redTextColor: cc.Color.RED,
        blackTextColor: cc.Color.BLACK,
        texSuitBig:{
            default:[],
            type:cc.SpriteFrame
        },
        texSuit:{
            default:[],
            type:cc.SpriteFrame
        },
        texSuitSmall:{
            default:[],
            type:cc.SpriteFrame
        }
    },

    // LIFE-CYCLE CALLBACKS:

     onLoad () {
         this.node.on(cc.Node.EventType.TOUCH_START,
             function(event){
             event.stopPropagation();
             if(this.isClick==0){
                 this.node.position=cc.v2(0,30).add(this.node.position)
                 this.isClick=1;
             }
             else {
                 this.node.position=cc.v2(0,-30).add(this.node.position)
                 this.isClick=0;
             }
             },this)
     },

    start () {

    },
    init(num){
        let suit=Math.floor(num/13);
        let point=num%13;
        console.log(suit);

        this.mainPic.spriteFrame=this.texSuitBig[suit]
        this.suit.spriteFrame=this.texSuitSmall[suit]
        if(suit%2==0){
            this.point.node.color=this.blackTextColor;
        }
        else {
            this.point.node.color=this.redTextColor;
        }
        if(point=="0"){
            this.point.string="A";
        }
        else if(point==53){
            this.point.string="joker";
        }
        else if(point==54){
            this.point.string="joker";
        }
        else if(point+1==11){
            this.point.string="J";

        }
        else if(point+1==12){
            this.point.string="Q";

        }
        else if(point+1==13){
            this.point.string="K";

        }
        else {
            this.point.string=point+1;
        }


    }

    // update (dt) {},
});
